<!--
 * @Author: xiaotiwen
 * @Date: 2020-05-08 18:14:47
 * @LastEditTime: 2020-07-21 18:00:25
 * @LastEditors: xiaotiwen
 * @FilePath: \eduweb\src\views\practiceManagement\scheduleSetting\index.vue
 * @Description: 排课管理
 -->
<template>
    <div>
        <inner-breadcrumb v-model="pathKey" :path="path"></inner-breadcrumb>
        <div v-if="pathKey ==='main'">
            <ConditionCard
                shadow="never"
                @search="onSubmit"
                @reset="reset('queryForm')"
                labelWidth="120px"
            >
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item :label="$t('label.schoolTerm')">
                            <CalendarSelect v-model="queryForm.yearTerm" @load-done="loadDone"></CalendarSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.grade')">
                            <el-date-picker
                                v-model="queryForm.grade"
                                value-format="yyyy"
                                type="year"
                                :placeholder="$t('message.plzSelect')"
                                style="width: 100%"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.trainingLevel')">
                            <DictSelect
                                v-model="queryForm.trainingLevel"
                                :data="options.trainingLevel"
                                :clearable="false"
                                :disabled="true"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item :label="$t('fundingManagement.label.courseOpenAcademy')">
                            <DictSelect
                                v-model="queryForm.courseOpenAcademyId"
                                :data="options.courseOpenAcademyId"
                                :clearable="false"
                                :filterable="true"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('courseConfirmation.label.stuFaculty')">
                            <DictSelect
                                v-model="queryForm.studentAcademyId"
                                :data="options.studentAcademyId"
                                :clearable="false"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('label.major')">
                            <MyMajor
                                :faculty="queryForm.studentAcademyId"
                                :grade="queryForm.grade"
                                v-model="queryForm.majorId"
                            ></MyMajor>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item :label="$t('fundingManagement.label.isPlaceMent')">
                            <DictSelect
                                v-model="queryForm.isSchedule"
                                :data="options.isUploadFileDisperse"
                                :clearable="false"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('fundingManagement.label.isClassBorrow')">
                            <DictSelect
                                v-model="queryForm.isClassBorrow"
                                :data="options.isUploadFileDisperse"
                                :clearable="false"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('scheduleSetting.label.isPublish')">
                            <DictSelect
                                v-model="queryForm.status"
                                :data="options.status"
                                :clearable="false"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item :label="$t('scheduleSetting.label.nature')">
                            <DictSelect
                                v-model="queryForm.practiceNature"
                                :data="options.practiceNature"
                                :clearable="false"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('message.startTime')">
                            <el-date-picker
                                v-model="queryForm.courseDateStart"
                                format="yyyy-MM-dd"
                                value-format="timestamp"
                                type="date"
                                style="width: 100%"
                                :placeholder="$t('message.plzSelect')"
                                :picker-options="pickerOptions1"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item :label="$t('message.endTime')">
                            <el-date-picker
                                v-model="queryForm.courseDateEnd"
                                format="yyyy-MM-dd"
                                value-format="timestamp"
                                type="date"
                                style="width: 100%"
                                :placeholder="$t('message.plzSelect')"
                                :picker-options="pickerOptions2"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="8">
                        <el-form-item
                            :label="$t('scheduleSetting.label.isUploadFileDisperse')"
                            label-width="180px"
                        >
                            <DictSelect
                                v-model="queryForm.isUploadFileDisperse"
                                :data="options.isUploadFileDisperse"
                                :clearable="false"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item
                            :label="$t('scheduleSetting.label.isUploadFileCentralize')"
                            label-width="180px"
                        >
                            <DictSelect
                                v-model="queryForm.isUploadFileCentralize"
                                :data="options.isUploadFileDisperse"
                                :clearable="false"
                            ></DictSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
            </ConditionCard>
            <el-card shadow="never" body-style="padding: 24px;">
                <h2 class="titles">{{$t('scheduleSetting.title.scheduleTitle')}}</h2>
                <div class="edu-opertion-bar">
                    <div class="float-left">
                        <KeywordInput v-model="queryForm.courseNoOrName" :placeholder="$t('courseConfirmation.tips.keyTips')" @enter="handSearchChang"></KeywordInput>
                        <!-- <el-input
                            style="width: 200px;"
                            v-model="queryForm.courseNoOrName"
                            :placeholder="$t('courseConfirmation.tips.keyTips')"
                            prefix-icon="el-icon-search"
                            @change="handSearchChang"
                        /> -->
                    </div>
                    <div class="float-right">
                        <el-dropdown v-if="authsBtnState.exportState" trigger="click" @command="handleExportSchemes" class="btn1">
                            <el-button>
                                {{$t('message.export')}}
                                <i class="el-icon-arrow-down el-icon--right"></i>
                            </el-button>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item
                                    style="width: 225px;"
                                    v-for="item in exportNames"
                                    :key="item.value"
                                    :command="item.value"
                                >{{$t('message.export')}}{{item.label}}</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                        <el-dropdown v-if="authsBtnState.downloadState" trigger="click" @command="downLoad">
                            <el-button>
                                {{$t('scheduleSetting.btn.download')}}
                                <i
                                    class="el-icon-arrow-down el-icon--right"
                                ></i>
                            </el-button>
                            <el-dropdown-menu slot="dropdown">
                                <el-dropdown-item
                                    style="width: 147px;"
                                    command="DISPERSE"
                                >{{$t('scheduleSetting.btn.download2')}}</el-dropdown-item>
                                <el-dropdown-item
                                    style="width: 147px;"
                                    command="CENTRALIZE"
                                >{{$t('scheduleSetting.btn.download3')}}</el-dropdown-item>
                            </el-dropdown-menu>
                        </el-dropdown>
                        <el-button v-if="authsBtnState.publishUnpublishState" type="primary" @click="publish">{{$t('message.publish')}}</el-button>
                        <el-button v-if="authsBtnState.publishUnpublishState" type="primary" @click="cancelPublish">{{$t('scheduleSetting.btn.cancelPublish')}}</el-button>
                        <el-button v-if="authsBtnState.classroomBorrowApply" type="primary" @click="classroomBorrow">{{$t('scheduleSetting.btn.classroomBorrow')}}</el-button>
                    </div>
                </div>
            </el-card>
            <edu-table
                ref="tables"
                :data="data"
                :order="true"
                :total="total"
                @page-change="pageChange"
                :selectFixed="true"
                :orderFixed="true"
            >
                <el-table-column
                    :min-width="item.width"
                    v-for="item in label"
                    :key="item.props"
                    :label="item.label"
                    :prop="item.props"
                    :sortable="item.sortable"
                    show-overflow-tooltip
                    :fixed="item.fixed"
                ></el-table-column>
                <el-table-column
                    min-width="80"
                    :label="$t('scheduleSetting.label.isPublish')"
                    prop="status"
                    show-overflow-tooltip
                    fixed="right"
                >
                  <template slot-scope="scope">
                    <el-tag v-if="scope.row.status == 'PUBLISH'" type="success">
                        {{ scope.row.statuss }}
                    </el-tag>
                    <el-tag v-if="scope.row.status == 'DRAFT'" type="warning">
                        {{ scope.row.statuss }}
                    </el-tag>
                  </template>
                </el-table-column>
                <el-table-column min-width="200px" :label="$t('message.operating')" fixed="right">
                    <template slot-scope="scope">
                        <div class="ReworkMana_btns" @click.stop>
                            <el-button type="text" @click="open('upload', scope.row)"
                                v-if="scope.row.isSchedule==='Y'&&scope.row.status==='PUBLISH'&&authsBtnState.uploadState">
                              {{$t('scheduleSetting.btn.upload')}}
                            </el-button>
                            <el-button v-if="scope.row.status =='PUBLISH'&&authsBtnState.classroomBorrowDetails" type="text" @click="open('classroomBorrowDetails', scope.row)">
                              {{$t('scheduleSetting.btn.classroomBorrowDetails')}}
                            </el-button>
                            <el-button type="text" @click="open('schedule', scope.row)" v-if="scope.row.status!=='PUBLISH'&&authsBtnState.scheduleState">
                              {{$t('scheduleSetting.btn.schedule')}}
                            </el-button>
                            <!--已发布并且具有排课权限，可进行修改-->
                            <el-button type="text" @click="open('editPublishSchedule', scope.row)" v-if="scope.row.status==='PUBLISH'&&authsBtnState.scheduleState">
                              {{$t('scheduleSetting.btn.edit')}}
                            </el-button>
                            <el-button v-if="authsBtnState.detailsState" type="text" @click="open('details', scope.row)">
                              {{$t('message.detail')}}
                            </el-button>
                        </div>
                    </template>
                </el-table-column>
            </edu-table>
        </div>
        <!-- 排课明细/ 上传 -->
      <classroomBorrow v-if="pathKey === 'classroomBorrow'" :objs="objs" @cancel="cancel"></classroomBorrow>

      <classroomBorrow v-if="pathKey === 'classroomBorrowView'" :pageType="'3'" :objs="courseInfo" :applyData="applydata" @cancel="cancel"></classroomBorrow>

      <classroomBorrowQuery v-if="pathKey === 'classroomBorrowDetails'" :objs="objs" @showDetails="showClassroomBorrowDetails"></classroomBorrowQuery>

        <schedule
            v-if="pathKey === 'schedule'||pathKey === 'upload' || pathKey === 'editPublishSchedule'"
            :objs="objs"
            :isEdit="isEdit"
            :editFlag="editFlag"
            @cancel="cancel"
            :scheduleFlag="scheduleFlag"
            @changePanel="changePanel"
        ></schedule>
        <!-- 排课 -->
        <schedulePanel v-if="pathKey === 'panel'"></schedulePanel>
        <!-- 查看详情 -->
        <scheduleDetails v-if="pathKey ==='details'" :ids="ids" :objs="objs" :scheduleFlag="scheduleFlag" @back="cancel"></scheduleDetails>
        <!-- 导出弹框 -->
        <el-dialog :title="$t('message.export')" :visible.sync="dialogFlag" width="450px">
            <el-form ref="forms" :model="forms" label-width="110px" :rules="rules">
                <el-row :gutter="24">
                    <el-col>
                        <el-form-item
                            :label="$t('fundingManagement.label.courseOpenAcademy')"
                            prop="obj"
                        >
                            <el-select v-model="forms.obj" value-key="value"  style="width:100%">
                                <el-option
                                    v-for="item in options.courseOpenAcademyId"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="24">
                        <el-form-item :label="$t('label.schoolTerm')" prop="yearTerm">
                            <CalendarSelect v-model="forms.yearTerm" style="width:100%"></CalendarSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col v-if="this.exportType==='collegeCoursesExport'">
                        <el-form-item
                            :label="$t('scheduleSetting.label.practiceStage')"
                            prop="isStage"
                        >
                            <el-select v-model="forms.stage" clearable  style="width:100%">
                                <el-option
                                    v-for="item in options.isStage"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogFlag = false">{{$t('message.cancel')}}</el-button>
                <el-button type="primary" @click="exportSure">{{$t('message.confirm')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import MyMajor from 'common/src/views/practiceManagement/common/MyMajor'
import { findDept } from 'common/src/api/user'
import schedule from './schedule'
import classroomBorrow from './classroomBorrow'
import classroomBorrowQuery from './classroomBorrowQuery'
import schedulePanel from './schedulePanel'
import scheduleDetails from './scheduleDetails'
import commonMixins from '../commonMixins'
import {
    getList,
    publicData,
    cancelPublicData,
    saveRoomDetails,
    exportArrange,
    exportPractice,
    exportFuns,
    downloadZip,
    getDetail
} from 'common/src/api/practiceManagement/scheduleSetting'
import { udgPtBaseInfoList } from 'common/src/api/practiceManagement/internSetup'
export default {
    // 组件名称
    name: 'scheduleSetting',
    // 局部注册的组件
    components: {
        MyMajor,
        schedule,
        schedulePanel,
        scheduleDetails,
        classroomBorrow,
        classroomBorrowQuery
    },
    mixins: [commonMixins],
    // 组件参数 接收来自父组件的数据
    props: {},
    // 组件状态值
    data() {
        return {
            courseInfo:{},
            applydata:{},
            calendarDate:[],
            scheduleFlag: false, // false校内实践, true校外实践
            isEdit:false,//是否是发布修改状态
            editFlag: false, // 是否允许编辑 true不允许编辑，false允许编辑
            dialogFlag: false,
            exportType: '',
            yearTerm: '',
            objs: {
                yearTerm: '',
                id: '',
                classId: '',
                courseOpenAcademyId: ''
            },
            page: {
                pageNum_: 1,
                pageSize_: 20
            },
            total: 0,
            queryForm: {
                yearTerm: '', // 学年学期
                grade: '', // 年级
                trainingLevel: 'UDG', // 培养层次
                studentAcademyId:'',//学生所属学院
                courseOpenAcademyId: '', // 学院院系
                majorId: '', // 专业
                isClassBorrow: '', // 教室借用
                courseNoOrName: '', // 课程代码或名称
                status: '', // 发布状态
                practiceNature: '', // 实践性质
                courseDateStart: '', // 开始时间
                courseDateEnd: '', // 结束时间
                isUploadFileDisperse: '', // 是否上传分散实习
                isUploadFileCentralize: '' // 是否上传实习总表
            },
            forms: {
                obj: { label: '', value: '' },
                yearTerm: '',
                stage: null
            },
            options: {
                trainingLevel: [
                    { label: this.$t('courseConfirmation.udg'), value: 'UDG' },
                    { label: this.$t('courseConfirmation.pre'), value: 'asdf' }
                ], // 培养层次
                courseOpenAcademyId: [],
                studentAcademyId:[],
                majorId: [],
                calendarName: [],
                status: [
                    { label: this.$t('scheduleSetting.status.unPublish'), value: 'DRAFT' },
                    { label: this.$t('scheduleSetting.status.publish'), value: 'PUBLISH' }
                ],
                practiceNature: [
                    { label: this.$t('fundingManagement.label.concentrated'), value: 'CENTRALIZE' },
                    { label: this.$t('fundingManagement.label.dispersion'), value: 'DISPERSE' }
                ],
                isUploadFileDisperse: [
                    { label: this.$t('message.yes'), value: 'Y' },
                    { label: this.$t('message.no'), value: 'N' }
                ],
                isStage: [
                    { label: this.$t('scheduleSetting.label.teachingWeek'), value: '0' },
                    { label: this.$t('scheduleSetting.label.practiceWeek'), value: '1' }
                ],
                compus: []
            },
            data: [],
            label: [
                {
                    label: this.$t('fundingManagement.label.courseProgramNumber'),
                    props: 'subCourseNo',
                    width: 100,
                    sortable: true,
                    fixed: 'left'
                },
                {
                    label: this.$t('fundingManagement.label.courseCode'),
                    props: 'courseCode',
                    width: 100,
                    sortable: true,
                    fixed: 'left'
                },
                {
                    label: this.$t('fundingManagement.label.courseName'),
                    props: 'courseName',
                    width: 180,
                    sortable: true,
                    fixed: 'left'
                },
                {
                    label: this.$t('fundingManagement.label.courseOpenAcademy'),
                    props: 'courseOpenAcademy',
                    width: 180,
                    sortable: true
                },
                {
                    label: this.$t('courseConfirmation.label.stuFaculty'),
                    props: 'studentAcademy',
                    width: 180,
                    sortable: true
                },
                { label: this.$t('label.grade'), props: 'grade', width: 80, sortable: true },
                { label: this.$t('label.major'), props: 'majorName', width: 160, sortable: true },
                {
                    label: this.$t('practiceTask.label.number'),
                    props: 'studentCount',
                    width: 80,
                    sortable: true
                },
                {
                    label: this.$t('label.trainingLevel'),
                    props: 'trainingLevels',
                    width: 80,
                    sortable: false
                },
                {
                    label: this.$t('fundingManagement.label.times'),
                    props: 'times',
                    width: 180,
                    sortable: true
                },
                {
                    label: this.$t('scheduleSetting.label.baseArea'),
                    props: 'baseAreaI18n',
                    width: 100,
                    sortable: true
                },
                {
                    label: this.$t('fundingManagement.label.courseAddr'),
                    props: 'addresss',
                    width: 130,
                    sortable: true
                },
                {
                    label: this.$t('fundingManagement.label.mainTeacherName'),
                    props: 'mainTeacherName',
                    width: 100,
                    sortable: true
                },
                {
                    label: this.$t('scheduleSetting.label.estimatedFund'),
                    props: 'funds',
                    width: 100,
                    sortable: true
                },
                {
                    label: this.$t('fundingManagement.label.isClassBorrow'),
                    props: 'isClassBorrows',
                    width: 100,
                    sortable: true
                },
                {
                    label: this.$t('scheduleSetting.label.nature'),
                    props: 'practiceNatures',
                    width: 100,
                    sortable: true
                }
            ],
            exportNames: [
                {
                    label: this.$t('scheduleSetting.sheet.sheetName1'),
                    value: 'exportArrange',
                    url: ''
                },
                {
                    label: this.$t('scheduleSetting.sheet.sheetName2'),
                    value: 'exportPractice',
                    url: ''
                },
                {
                    label: this.$t('scheduleSetting.sheet.sheetName3'),
                    value: 'ptTaskExport',
                    url: 'udgPtReportExport/ptTaskExport'
                },
                {
                    label: this.$t('scheduleSetting.sheet.sheetName4'),
                    value: 'ptClassArrangeExport',
                    url: 'udgPtReportExport/ptClassArrangeExport'
                },
                {
                    label: this.$t('scheduleSetting.sheet.sheetName5'),
                    value: 'collegeCoursesExport',
                    url: 'udgPtReportExport/collegeCoursesExport'
                },
                {
                    label: this.$t('scheduleSetting.sheet.sheetName6'),
                    value: 'classRoomArrangeExport',
                    url: 'udgPtReportExport/classRoomArrangeExport'
                },
                {
                    label: this.$t('scheduleSetting.sheet.sheetName7'),
                    value: 'classRoomApplyExport',
                    url: 'udgPtReportExport/classRoomApplyExport'
                }
            ],
            pathKey: 'main',
            path: {
                label: this.$t('scheduleSetting.path.pathLabel'),
                key: 'main',
                disable: false,
                children: [
                    {
                        label: this.$t('scheduleSetting.path.childrenLabel1'),
                        key: 'details',
                        disable: true
                    },
                    {
                        label: this.$t('scheduleSetting.path.childrenLabel2'),
                        key: 'upload',
                        disable: true
                    },
                    {
                        label: this.$t('scheduleSetting.path.childrenLabel3'),
                        key: 'schedule',
                        disable: false,
                        children: [
                            {
                                label: this.$t('scheduleSetting.path.childrenLabel4'),
                                key: 'panel',
                                disable: true
                            }
                        ]
                    },
                    {
                        label: this.$t('scheduleSetting.path.childrenLabel7'),
                        key: 'editPublishSchedule',
                        disable: true
                    },
                    {
                        label: this.$t('scheduleSetting.path.childrenLabel5'),
                        key: 'classroomBorrow',
                        disable: true
                    },
                    {
                        label: this.$t('scheduleSetting.path.childrenLabel6'),
                        key: 'classroomBorrowDetails',
                        disable: false,
                        children: [
                            {
                                label: this.$t('scheduleSetting.path.childrenLabel5'),
                                key: 'classroomBorrowView',
                                disable: true
                            }
                        ]
                    }
                ]
            },
            rules: {
                obj: {
                    required: true,
                    validator: this.validateSurnmae,
                    trigger: ['change']
                },
                yearTerm: {
                    required: true,
                    message: this.$t('practiceReworkManagement.tips.mustWrite'),
                    trigger: ['change']
                }
            },
            pickerOptions1: {
                disabledDate: time => {
                    if (this.queryForm.courseDateEnd) {
                        return (
                            time.getTime() >
                            new Date(this.queryForm.courseDateEnd).getTime() - 86400000
                        )
                    }
                }
            },
            pickerOptions2: {
                disabledDate: time => {
                    if (this.queryForm.courseDateStart) {
                        return (
                            time.getTime() <
                            new Date(this.queryForm.courseDateStart).getTime() + 86400000
                        )
                    }
                }
            },
            auths: [],
            authsBtnState: {
              scheduleState: false, // 排课
              downloadState: false, // 下载
              uploadState: false,   // 上传
              exportState: false,   // 导出
              publishUnpublishState: false, // 发布/取消发布
              detailsState: false, // 详情
              classroomBorrowApply:false,//教室借用申请
              classroomBorrowDetails:false,//教室借用详情
              editState:false,//修改
            }
        }
    },
    // 计算属性
    computed: {},
    // 侦听器
    watch: {
      auths: {
        handler(newVal) {
          if (newVal && Array.isArray(newVal) && newVal.length > 0) {
            newVal.some(item => {
              // 排课
              if (item.authCode === 'scheduleSetting-schedule') {
                this.authsBtnState.scheduleState = true;
              }
              // 下载
              if (item.authCode === 'scheduleSetting-download') {
                this.authsBtnState.downloadState = true;
              }
              // 上传
              if (item.authCode === 'scheduleSetting-upload') {
                this.authsBtnState.uploadState = true;
              }
              // 导出
              if (item.authCode === 'scheduleSetting-export') {
                this.authsBtnState.exportState = true;
              }
              // 发布/取消发布
              if (item.authCode === 'scheduleSetting-publish/unpublish') {
                this.authsBtnState.publishUnpublishState = true;
              }
              // 详情
              if (item.authCode === 'scheduleSetting-details') {
                this.authsBtnState.detailsState = true;
              }
              // 教室借用申请
              if (item.authCode === 'scheduleSetting-classroomBorrow') {
                  this.authsBtnState.classroomBorrowApply = true;
              }
              // 教室借用详情
              if (item.authCode === 'scheduleSetting-classroomBorrowDetails') {
                  this.authsBtnState.classroomBorrowDetails = true;
              }
              // 发布后修改
              if (item.authCode === 'scheduleSetting-editPublishSchedule') {
                  this.authsBtnState.editState = true;
              }
            });
          }
        }
      }
    },
    /**
     * 在实例初始化之后，组件属性计算之前，如data属性等
     */
    created() {
      // 获取当前用户auths权限
      if (localStorage.getItem("sessiondata")) {
        if (JSON.parse(localStorage.getItem("sessiondata")).auths) {
          this.auths = JSON.parse(localStorage.getItem("sessiondata")).auths;
        }
      }
    },
    /**
     * 在挂载开始之前被调用：相关的 render 函数首次被调用。
     */
    mounted() {
        let param = {
            X_YX: 'courseOpenAcademyId', // 学院
            X_XQ: 'compus' // 校区
        }
        this.initOptions(param)
        findDept(0).then(res => {
            if (res.code == 200 && res.data) {
                this.options.studentAcademyId = res.data.map(row => {
                    return { label: row.deptName, value: row.deptCode }
                })
            }
        })
    },
    // 组件方法
    methods: {
        validateSurnmae(rule, value, callback) {
            if (!this.forms.obj.label && this.forms.obj.label === '') {
                return callback(new Error(this.$t('fundingManagement.tips.plzInput')))
            } else {
                return callback()
            }
        },
        open(val, row) {
            this.ids = row.id
            this.objs.yearTerm = this.yearTerms
            this.objs.id = this.ids
            this.objs.classId = row.subCourseNo
            this.objs.isSchedule = row.isSchedule
            this.objs.courseOpenAcademyId = row.courseOpenAcademyId

            if(val === 'classroomBorrowDetails'){
                //教室借用详情
                this.objs = row
                this.objs.yearTerm = this.yearTerms
            }
            this.isEdit = false
            if (val === 'upload') {
                // 上传
                this.editFlag = true
            } else {
                this.editFlag = false
                if(val === 'editPublishSchedule'){
                    this.isEdit = true
                }
            }
            if (val === 'schedule' || val === 'editPublishSchedule') {
                this.timeSetBtns(row.yearTerm).then(res => {
                    if (res) {
                        this.pathKey = val
                    }
                })
            } else {
                this.pathKey = val
            }
        },
        classroomBorrow() {
            // 教室借用
            let selection = this.$refs.tables.selectionDatas
            if (!selection || selection.length === 0) {
                this.$noSelectAlert()
                return
            }else if(selection.length > 1){
                this.$message({ message: this.$t('scheduleSetting.tips.onlyOne'), type: 'warning' })
                return
            }
            this.objs = selection[0];
            if(this.objs.status !== 'PUBLISH'){
                this.$message({ message: this.$t('scheduleSetting.tips.classroomSelectTip1'), type: 'warning' })
                return
            }
            this.objs.yearTerm = this.yearTerms
            this.editFlag = false
            this.pathKey = 'classroomBorrow'
        },


        publish() {
            // 发布
            let selection = this.$refs.tables.selectionDatas
            if (!selection || selection.length === 0) {
                this.$noSelectAlert()
                return
            }
            let jsonData = []
            let count = 0
            selection.forEach(item => {
                if(item.status === 'PUBLISH'){
                    count++
                }
                jsonData.push({ id: item.id })
            })
            if(count > 0){
                this.$message({ message: this.$t('scheduleSetting.tips.confirmStatus'), type: 'warning' })
                return
            }
            this.$confirm(
                this.$t('scheduleSetting.tips.confirmPublish'),
                this.$t('message.prompt'),
                {
                    confirmButtonText: this.$t('message.confirm'),
                    cancelButtonText: this.$t('message.cancel'),
                    type: 'warning'
                }
            ).then(res => {
                publicData(jsonData).then(res => {
                    if (res && res.code !== 200) {
                        this.$message({ message: res.msg, type: 'warning' })
                        return
                    }
                    this.getLists(true)
                    this.$message({
                        type: 'success',
                        message: this.$t('scheduleSetting.tips.publishSuccess')
                    })
                })
            })
        },
        cancelPublish() {
            // 取消发布
            let selection = this.$refs.tables.selectionDatas
            if (!selection || selection.length === 0) {
                this.$noSelectAlert()
                return
            }
            let jsonData = []
            let count = 0
            selection.forEach(item => {
                if(item.status !== 'PUBLISH'){
                    count++
                }
                jsonData.push({ id: item.id })
            })
            if(count > 0){
                this.$message({ message: this.$t('scheduleSetting.tips.cancelStatus'), type: 'warning' })
                return
            }
            this.$confirm(
                this.$t('scheduleSetting.tips.confirmCancelPublish'),
                this.$t('message.prompt'),
                {
                    confirmButtonText: this.$t('message.confirm'),
                    cancelButtonText: this.$t('message.cancel'),
                    type: 'warning'
                }
            ).then(res => {
                cancelPublicData(jsonData).then(res => {
                    if (res && res.code !== 200) {
                        this.$message({ message: res.msg, type: 'warning' })
                        return
                    }
                    this.getLists(true)
                    this.$message({
                        type: 'success',
                        message: this.$t('scheduleSetting.tips.cancelSuccess')
                    })
                })
            })
        },
        changePanel() {
            // 排课
            this.pathKey = 'panel'
        },
        handleExportSchemes(type) {
            // 导出
            let selection = this.$refs.tables.selectionDatas
            let idArr = []
            if (selection && selection.length > 0) {
                idArr = selection.map(item => {
                    return item.id
                })
            }
            if (type === 'exportPractice') {
                let params = {
                    udgPtClassInfoDto: this.queryForm,
                    ids: idArr,
                    exportType: selection && selection.length > 0 ? 1 : 0
                }
                exportPractice(params)
            } else {
                this.dialogFlag = true
                this.exportType = type
            }
        },
        exportSure() {
            this.$refs.forms.validate(valid => {
                if (valid) {
                    if (this.exportType === 'exportArrange') {
                        let params = {
                            yearTerm: this.forms.yearTerm,
                            academyName: this.forms.obj.label,
                            academyId: this.forms.obj.value
                        }
                        let schoolTerm = this.calendarDate.find(v=>{return v.id === params.yearTerm})
                        exportArrange(params,params.academyName+"-"+schoolTerm.fullName)
                    } else {
                        let params = {
                            yearTerm: this.forms.yearTerm,
                            academyId: this.forms.obj.value,
                            academyName: this.forms.obj.label,
                            stage:this.forms.stage
                        }
                        let name = this.fieldChange(this.exportNames, this.exportType)
                        let url = this.fieldChange(this.exportNames, this.exportType, [
                            'url',
                            'value'
                        ])
                        exportFuns(params, name, url)
                    }
                    this.dialogFlag = false
                }
            })
        },
        functions() {
            return this.exportType
        },
        downLoad(type) {
            let selection = this.$refs.tables.selectionDatas
            let idArr = []
            let flags = false
            if (!selection || selection.length <= 0) {
                this.$message({
                    type: 'warning',
                    message: this.$t('scheduleSetting.tips.plzDownload')
                })
                return
            }
            let name = ''
            let filed = ''
            if (type === 'DISPERSE') {
                name = '分散实习表'
                filed = 'isUploadFileDisperse'
            } else {
                name = '实习总结表'
                filed = 'isUploadFileCentralize'
            }
            selection.map(item => {
                if (item[filed] !== 'Y') {
                    flags = true
                    return
                }
                idArr.push(item.id)
            })
            if (flags) {
                this.$message({
                    type: 'warning',
                    message: this.$t('scheduleSetting.tips.noCourse') + `${name}`
                })
                return
            }
            let jsonData = {
                type: type,
                ids: idArr
            }
            let types = '.zip'
            if (selection.length === 1) {
                getDetail({ id: selection[0].id }).then(res => {
                    let arr = res.data.udgPtAttachT.attachName.split('.')
                    types = arr[arr.length - 1]
                    downloadZip(jsonData, `${name}.${types}`)
                })
            } else {
                downloadZip(jsonData, name + types)
            }
        },
        handSearchChang() {
            // 搜索
            this.getLists(true)
        },
        reset() {
            // 重置
            for (const key in this.queryForm) {
                if (key !== 'yearTerm') {
                    this.queryForm[key] = ''
                }
            }
            this.queryForm.yearTerm = this.yearTerms
            this.queryForm.trainingLevel = 'UDG'
            this.getLists(true)
        },
        onSubmit() {
            // 筛选
            this.getLists(true)
        },
        getLists(refresh) {
            // 获取列表
            if (refresh) {
                this.page.pageNum_ = 1;
                if(this.$refs.tables) {
                  this.$refs.tables.pageNum = 1;
                }
            }
            if (this.timeChange()) {
                return
            }
            let jsons = {
                condition: this.queryForm,
                pageNum_: this.page.pageNum_,
                pageSize_: this.page.pageSize_
            }
            getList(jsons).then(res => {
                if (res.data.list || res.data.list.length > 0) {
                    this.data = res.data.list
                    this.total = res.data.total_
                    this.data.forEach((item, idx) => {
                        let times = []
                        if (item.courseDateStart) {
                            times.push(
                                this.formatDate(new Date(item.courseDateStart), 'yyyy-MM-dd')
                            )
                        }
                        if (item.courseDateEnd) {
                            times.push(this.formatDate(new Date(item.courseDateEnd), 'yyyy-MM-dd'))
                        }
                        this.$set(
                            item,
                            'statuss',
                            this.changeType(item.status, this.options.status)
                        )
                        this.$set(
                            item,
                            'practiceNatures',
                            this.changeType(item.practiceNature, this.options.practiceNature)
                        )
                        this.$set(
                            item,
                            'trainingLevels',
                            this.changeType(item.trainingLevel, this.options.trainingLevel)
                        )
                        this.$set(
                            item,
                            'isClassBorrows',
                            this.changeType(item.isClassBorrow, this.options.isUploadFileDisperse)
                        )
                        this.$set(item, 'times', times.join('~'))
                        if (item.baseArea === '410001') {
                            this.$set(
                                item,
                                'addresss',
                                this.changeType(item.compus, this.options.compus)
                            )
                        } else if (item.courseAddr) {
                            this.$set(item, 'addresss', item.courseAddr)
                            // this.getAddress(item, idx)
                        }
                    })
                }
            })
        },
        loadDone(data) {
            // 获取初始学年
            this.yearTerms = this.queryForm.yearTerm
            this.calendarDate = data;
            this.getLists();
        },
        timeChange() {
            // 时间校验
            if (this.queryForm.courseDateStart && this.queryForm.courseDateEnd) {
                if (this.queryForm.courseDateStart > this.queryForm.courseDateEnd) {
                    this.$message({
                        type: 'warning',
                        message: this.$t('dispersionPracticeApply.tips.timeCheck')
                    })
                    return true
                }
            }
        },
        pageChange(val) {
            // 分页切换功能
            ;[this.page.pageNum_, this.page.pageSize_] = [val.pageNum, val.pageSize]
            this.getLists()
        },
        cancel(val) {
            // 返回
            this.pathKey = 'main'
            if (val === 'refresh') {
                this.getLists(true)
            }
        },
        showClassroomBorrowDetails(val){
            console.info(val)
            // 返回
            this.pathKey = 'classroomBorrowView'
            this.courseInfo = val.courseInfo
            this.applydata = val.obj
        },
        getAddress(datas, idx) {
            let jsonData = {
                baseName: datas.courseAddr,
                signConFlag: '',
                status: 'APPROVED',
                effectStatus: 'Y',
                practiceArea: datas.baseArea,
                academyId: '',
                brilliantBaseFlag: '',
                validDateStart: new Date(datas.courseDateStart).getTime(),
                validDateEnd: new Date(datas.courseDateEnd).getTime()
            }
            udgPtBaseInfoList(1, 50, jsonData).then(res => {
                if (res.data.records.length > 0) {
                    this.$set(this.data[idx], 'addresss', res.data.records[0].label)
                } else {
                    this.$set(this.data[idx], 'addresss', datas.courseAddr)
                }
            })
        }
    }
}
</script>
<style lang="scss" scoped>
.titles {
    font-weight: bold;
    color: #2b3b4e;
}
.btn1 {
    margin-right: 10px;
}
.ReworkMana_btns {
    display: flex;
    justify-content: space-between;
}
</style>
